import logging

from aiogram import Bot, types
from aiogram_dialog import Dialog, DialogManager, Window
from aiogram_dialog.widgets.input import TextInput
from aiogram_dialog.widgets.kbd import Button, Cancel, Url
from aiogram_dialog.widgets.text import Format

from src.presentation.tg_bot.dialogs.widgets import LocaleText
from src.presentation.tg_bot.states import PaymentSG

from .handlers import check_payment, get_usd_rate, set_payment_amount

set_amount_window = Window(
    LocaleText("select-payment-amount", usd_rate="{usd_rate}"),
    TextInput("payment_amount", str, on_success=set_payment_amount),
    Cancel(LocaleText("back-btn")),
    state=PaymentSG.select_amount,
    getter=get_usd_rate,
)

check_payment_window = Window(
    LocaleText("payment-msg", payment_summ="{dialog_data[payment_summ]}"),
    Url(LocaleText("pay-btn"), Format("{dialog_data[bill_link]}")),
    Button(LocaleText("check-payment-btn"), id="check_payment_btn", on_click=check_payment),
    state=PaymentSG.create_payment,
)

create_payment_dialog = Dialog(set_amount_window, check_payment_window)
